<div class="layui-form" lay-filter="layuiadmin-form-tags" id="layuiadmin-form">
    <div class="layui-form-item">
        <label class="layui-form-label">分类名</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
            <input type="text" name="title" value="{{ d.params.title || '' }}" lay-verify="required"
                       placeholder="请输入..." autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级分类</label>
        <div class="layui-input-inline">
            <select name="pid" class="layui-select">
                <option value="">顶级</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">缩略图</label>
        <div class="layui-input-inline">
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="imageBtn">上传图片</button>
                <div class="layui-upload-list">
                    <script type="text/html" template>
                    {{# if(d.params.image){ }}
                    <img class="layui-upload-img" id="image" src="{{ d.params.image }}">
                    {{# }else{ }}
                    <img class="layui-upload-img" id="image">
                    {{# } }}
                    </script>
                </div>
            </div>
            <input type="hidden" name="image" v-model="find.image">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <textarea name="description" class="layui-textarea">{{ d.params.description || '' }}</textarea>
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="layuiadmin-submit" value="确认" class="layui-btn">
        </div>
    </div>
</div>
<style>
    #image{
        width: 150px;
        height: 150px;
    }
</style>
<script>
    layui.use(['form', 'helper', 'laytpl', 'upload', 'element'], function () {
        var form = layui.form,
            $ = layui.$,
            setter = layui.setter,
            helper = layui.helper;
        form.render('select');
        setTimeout(function(){
            $('.layui-upload-img').each((e, item) => {
                let id = $(item).attr('id')
                let renderId = '#' + id + 'Btn';
                helper.uploadRender(renderId , setter.requestUrl + '/upload' , function(res){
                    $(item).attr('src', res.data.path);
                    $('input[name=' + id + ']').val(res.data.url);
                });
            })
        } , 500)
    });
</script>